In [1]:
from rsplib.processing import RSPSource, StreamReasoner

In [2]:
jasper = StreamReasoner("http://jasper", 8182);
jasper.status()


{"name":"jasper","host":"jasper/","runUUID":"1942f959-bd9c-11e7-b124-1a00a83a5601","port":8182,"empty_results":false,"inference":false,"timestam_function":false,"backloop":false,"num_streams":0,"num_datasets":0,"num_queries":0}
Out[2]:
{'backloop': False,
 'empty_results': False,
 'host': 'jasper/',
 'inference': False,
 'name': 'jasper',
 'num_datasets': 0,
 'num_queries': 0,
 'num_streams': 0,
 'port': 8182,
 'runUUID': '1942f959-bd9c-11e7-b124-1a00a83a5601',
 'timestam_function': False}

Load Some rules from our file, e.g. RDFS entailment


In [3]:
with open('rdfs.rules.txt', 'r') as rule_file:
    rdfs=rule_file.read()
rdfs


Out[3]:
'[rdf1and4: (?x ?p ?y) -> (?p rdf:type rdf:Property), (?x rdf:type rdfs:Resource), (?y rdf:type rdfs:Resource)]\n[rdfs7b: (?a rdf:type rdfs:Class) -> (?a rdfs:subClassOf rdfs:Resource)] \n\n[rdfs2:  (?x ?p ?y), (?p rdfs:domain ?c) -> (?x rdf:type ?c)] \n[rdfs3:  (?x ?p ?y), (?p rdfs:range ?c) -> (?y rdf:type ?c)] \n[rdfs5a: (?a rdfs:subPropertyOf ?b), (?b rdfs:subPropertyOf ?c) -> (?a rdfs:subPropertyOf ?c)] \n[rdfs5b: (?a rdf:type rdf:Property) -> (?a rdfs:subPropertyOf ?a)] \n[rdfs6:  (?a ?p ?b), (?p rdfs:subPropertyOf ?q) -> (?a ?q ?b)] \n[rdfs7:  (?a rdf:type rdfs:Class) -> (?a rdfs:subClassOf ?a)]\n[rdfs8:  (?a rdfs:subClassOf ?b), (?b rdfs:subClassOf ?c) -> (?a rdfs:subClassOf ?c)] \n[rdfs9:  (?x rdfs:subClassOf ?y), (?a rdf:type ?x) -> (?a rdf:type ?y)] \n[rdfs10: (?x rdf:type rdfs:ContainerMembershipProperty) -> (?x rdfs:subPropertyOf rdfs:member)] \n'

Register RuleSet


In [4]:
jasper.register_rules("rdfs", rdfs)


{'ruleset': 'rdfs', 'rules': '[rdf1and4: (?x ?p ?y) -> (?p rdf:type rdf:Property), (?x rdf:type rdfs:Resource), (?y rdf:type rdfs:Resource)]\n[rdfs7b: (?a rdf:type rdfs:Class) -> (?a rdfs:subClassOf rdfs:Resource)] \n\n[rdfs2:  (?x ?p ?y), (?p rdfs:domain ?c) -> (?x rdf:type ?c)] \n[rdfs3:  (?x ?p ?y), (?p rdfs:range ?c) -> (?y rdf:type ?c)] \n[rdfs5a: (?a rdfs:subPropertyOf ?b), (?b rdfs:subPropertyOf ?c) -> (?a rdfs:subPropertyOf ?c)] \n[rdfs5b: (?a rdf:type rdf:Property) -> (?a rdfs:subPropertyOf ?a)] \n[rdfs6:  (?a ?p ?b), (?p rdfs:subPropertyOf ?q) -> (?a ?q ?b)] \n[rdfs7:  (?a rdf:type rdfs:Class) -> (?a rdfs:subClassOf ?a)]\n[rdfs8:  (?a rdfs:subClassOf ?b), (?b rdfs:subClassOf ?c) -> (?a rdfs:subClassOf ?c)] \n[rdfs9:  (?x rdfs:subClassOf ?y), (?a rdf:type ?x) -> (?a rdf:type ?y)] \n[rdfs10: (?x rdf:type rdfs:ContainerMembershipProperty) -> (?x rdfs:subPropertyOf rdfs:member)] \n'}
"Rules rdfs sucessfully registered"
Out[4]:
'Rules rdfs sucessfully registered'

In [5]:
jasper.rules()


[{"id":"rdfs","status":"STATIC"}]
Out[5]:
[{'id': 'rdfs', 'status': 'STATIC'}]

In [6]:
jasper.register_stream("AarhusTrafficData158505", "http://aarhustrafficdata158505:4001/sgraph")


"Stream AarhusTrafficData158505 succesfully registered with IRI http://aarhustrafficdata158505:4001/sgraph"
Out[6]:
'Stream AarhusTrafficData158505 succesfully registered with IRI http://aarhustrafficdata158505:4001/sgraph'

In [7]:
with open('q3.rspql.txt', 'r') as rspql_query:
   body = rspql_query.read()
   print(body)


CONSTRUCT {?s ?p ?o}
FROM NAMED WINDOW <win1> [RANGE 30s , SLIDE 5s] ON STREAM <AarhusTrafficData158505>
WHERE  { WINDOW ?w { ?s ?p ?o }}

Our Reasoning is Based on a Terminological Box


In [8]:
tbox = "https://raw.githubusercontent.com/streamreasoning/rsplab/tutorial/collector/lab/streamapp/tbox.rdf"

In [9]:
jasper.register_query("unionstrm", "STREAM", body, "rdfs", tbox)


{'queryBody': 'REGISTER STREAM <unionstrm> AS CONSTRUCT {?s ?p ?o}\nFROM NAMED WINDOW <win1> [RANGE 30s , SLIDE 5s] ON STREAM <AarhusTrafficData158505>\nWHERE  { WINDOW ?w { ?s ?p ?o }}', 'tbox': 'https://raw.githubusercontent.com/streamreasoning/rsplab/tutorial/collector/lab/streamapp/tbox.rdf', 'ruleset': 'rdfs'}
"Query unionstrm succesfully registered"
Out[9]:
'Query unionstrm succesfully registered'

In [10]:
jasper.register_observer("unionstrm", "default", {"host":"localhost","type":"ws","port":9103,"name":"default"})


"http://jasper:8182/queries/unionstrm/observers/default"
Out[10]:
'http://jasper:8182/queries/unionstrm/observers/default'

In [ ]: